package com.heima.wemedia;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

/**
 * @作者 itcast
 * @创建日期 2021/9/26 10:55
 **/
@SpringBootTest
@RunWith(SpringRunner.class)
public class PublishMessage {


    @Autowired
    RabbitTemplate rabbitTemplate;


    @Test
    public void pubArticle(){
        rabbitTemplate.convertAndSend("publish.article.topic","publish.article","11");
    }
    @Test
    public void lazyPubArticle(){
        rabbitTemplate.convertAndSend("publish.article.topic", "dead.publish.article", "12", new MessagePostProcessor() {
            @Override
            public Message postProcessMessage(Message message) throws AmqpException {
                // 设置消息的失效时间
                message.getMessageProperties().setExpiration("60000");// 单位毫秒
                return message;
            }
        });
    }
}
